$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'production/erporderproduction/list',
        datatype: "json",
        colModel: [
            {
                label: '操作', width: 50, align: 'center',
                formatter: function (value, options, row) {
                    // 生产单生产状态:1.待生产,2.生产中,3.生产完成,4.取消,5.待收货,6.已收货
                    var productionStatus = row.productionStatus;
                    // 生产商类型:1.紫云外协商;2.自营门店;3.小B;4.报价工厂
                    var producerType = row.producerType;
                    if (producerType == 1){
                        if (productionStatus == 2){
                            return '<a href="javascript:;" onclick="return supplierConfirmReceive(\'' + options.rowId + '\');">验货确定</a>';
                        }
                    }else {
                        // 分配订单收货状态 0:未收货，1:已收货
                        var allotReceivedStatus = row.allotReceivedStatus == null ? 0 : row.allotReceivedStatus;
                        // 生产单财务审核状态:1.待审核,2.待付款,3.已付款,11.作废
                        var financeStatus = row.financeStatus;
                        if (productionStatus == 3){
                            if (allotReceivedStatus == 0){
                                return '<a href="javascript:;" onclick="return confirmReceive(\'' + options.rowId + '\');">验货确定</a>';
                            }else{
                                if (financeStatus == 1){
                                    return '<a href="javascript:;" onclick="return auditFinish(\'' + options.rowId + '\');">审核完成</a>';
                                }
                            }
                        }
                    }
                    return '--';
                }
            },
            {
                label: '打印', width: 45, align: 'center', title: false,
                formatter: function (value, options, row) {
                    var actions = [];
                    actions.push('<a href="javascript:void(0);" onclick="return vm.printGoods(\'' + row.orderNo + '\');">送</a>&nbsp;&nbsp;|');
                    actions.push('<a href="javascript:void(0);" onclick="return vm.showEMS(\'' + row.orderNo + '\');">递</a>');
                    return actions.join('  ');
                }
            },
            {label: 'productionId', name: 'productionId', index: 'production_id', key: true,hidden:true, align: 'center'},
            {label: '原订单号', name: 'orderNo', index: 'order_no', width: 100, align: 'center',
                formatter: function (value) {
                    return '<a href="javascript:;" onclick="return window.erporderAllotPageVm.getInfo(\'' + value + '\');">'+ value +'</a>'
                }
            },
            {label: '金额', name: 'payableAmount', index: 'payable_amount', width: 60, align: 'center'},
            {label: '产品名称', name: 'erpItemName', index: '', width: 60, align: 'center'},
            {label: '产品规格', name: 'addon', index: 'addon', width: 130, align: 'center',
                formatter: function (value) {
                    return vm.parsingAddon(value)
                }
            },
            {label: '分配时间', name: 'createTime', index: 'create_time', width: 100, align: 'center'},
            {label: '工序', name: 'attributeName', index: 'attribute_name', width: 100, align: 'center'},
            {label: '数量', name: 'nums', index: 'nums', width: 40, align: 'center'},
            {label: '单位', name: 'unit', index: 'unit', width: 40, align: 'center'},
            {
                label: '生产状态',
                name: 'productionStatus',
                index: 'production_status',
                width: 50,
                align: 'center',
                hidden: true,
                align: 'center'
            },
            {
                label: '生产状态', name: '', index: 'production_status', width: 50, align: 'center',
                formatter: function (value, options, row) {
                    var valueText = "";
                    var userData = $("#jqGrid").jqGrid('getGridParam', 'userData');
                    $.each(userData.orderProductionStatusEnum, function (index, module) {
                        if (module.id == row.productionStatus) {
                            valueText = module.describe;
                            return false;
                        }
                    });
                    return valueText;
                }
            },
            {
                label: '发货状态', name: 'shipStatus', index: 'ship_status', width: 50, align: 'center',
                formatter: function (value) {
                    return value == 0 ? '未发货' : '已发货';
                }
            },
            {
                label: '财务状态', name: 'financeStatus', index: 'finance_status', width: 50, align: 'center',
                formatter: function (value, options, row) {
                    var valueText = "";
                    var userData = $("#jqGrid").jqGrid('getGridParam', 'userData');
                    $.each(userData.financeStatusEnum, function (index, module) {
                        if (module.id == row.financeStatus) {
                            valueText = module.describe;
                            return false;
                        }
                    });
                    return valueText;
                }
            },
            {label: '提现方式', name: 'onlineCash', width: 80, align: 'center',
                formatter: function (value) {
                   return value == 0 ? '线下' : '线上';
                }
            },
            {label: '生产商', name: 'producerName', index: 'producerName', width: 120, align: 'center'},
            {label: '源文件', name: '', index: '', width: 50, align: 'center',
                formatter: function (value, options, row) {
                    return '<a href="javascript:;" onclick="return vm.itemSourcePicsShow(\'' + options.rowId + '\');">下载</a>';
                }
            },
            {label: '图片', name: 'sendPicsUrl', index: '', width: 35, align: 'center',
                formatter: function (value, options, row) {
                    if (!isBlank(value)){
                        var size = row.size;
                        if (!isBlank(size)){
                            var s = parseFloat(size) / 1024 / 1024;
                            if (s >= 10){
                                return '<a target="_blank" href="'+window.parent.vm.ossHost + value +'">预览</a>';
                            }
                            var extArr = ['jpg', 'png','bmp', 'gif', 'webp', 'tiff'];
                            var ext = value.substring(value.lastIndexOf('.') + 1, value.length);
                            if (extArr.indexOf(ext) != -1){
                                if (s >= 5){
                                    return '<img class="img-thumbnail" src="'+window.parent.vm.ossHost + value +'?x-oss-process=image/quality,q_50">';
                                }
                            }
                        }
                        return '<img class="img-thumbnail" src="'+window.parent.vm.ossHost + value +'">';
                    }
                    return '';
                }
            },
            {label: '跟单员', name: 'pmcName', width: 50, align: 'center'},
            {label: '第三方单号', name: 'productionOrder', width: 100, align: 'center'},
            {label: '第三方发货状态', name: 'allotShipStatus', width: 100, align: 'center',
                formatter: function (value, options, row) {
                    var onlineCash = row.onlineCash;
                    if (onlineCash == 1){
                        return value == 0 ? '未发货' : '已发货';
                    }
                    return '';
                }
            },
            {label: '总额', name: 'allotTotalAmount', index: '', width: 50, align: 'center'},
            {label: '调价', name: 'allotDiscount', index: '', width: 50, align: 'center',
                formatter: function (value, options, row) {
                    if (value == null){
                        return '';
                    }
                    return '<a href="javascript:;" style="cursor: pointer;color:red;" onclick="return vm.discountView(\''+ row.productionId +'\',\''+ value +'\');">'+ value +'</a>';
                }
            },
            {label: '应付金额', name: 'allotPayableAmount', index: '', width: 50, align: 'center'},
        ],
        viewrecords: true,
        height: window.innerHeight - 120,
        rowNum: 25,
        rowList: [25, 50, 100],
        rownumbers: true,
        rownumWidth: 40,
        autowidth: true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader: {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount",
            userdata: "userData"
        },
        prmNames: {
            page: "page",
            rows: "limit",
            order: "order"
        },
        gridComplete: function () {
            // 图片预览初始化
            $('.img-thumbnail').viewer();

            var userData = $("#jqGrid").jqGrid('getGridParam', 'userData');
            vm.e.orderProductionStatusEnum = userData.orderProductionStatusEnum;
            vm.e.producerTypeEnum = userData.producerTypeEnum;
            vm.e.goodsTypeEnum = userData.goodsTypeEnum;
            vm.e.financeStatusEnum = userData.financeStatusEnum;
            vm.sellerInfoList = userData.sellerInfoList;
            vm.pmcIdList = userData.pmcIdList;
        }
    });
    // 显示序号
    $("#jqGrid").jqGrid('setLabel',0, '序号', '{width:80}');
});

/**
 * 外协单验货确定
 */
function supplierConfirmReceive(rowId) {
    var rowData = $("#jqGrid").jqGrid('getRowData', rowId);
    var orderNo = rowData.orderNo;
    var message = "单号：<span class='text-primary'>"+ orderNo +"</span> 是否验货确定？";
    confirm(message, function(){
        var productionId = rowData.productionId;
        $.ajax({
            type: "GET",
            url: baseURL + "production/erporderproduction/supplierConfirmReceive",
            contentType: "application/json",
            data: {
                'productionId': productionId,
            },
            success: function(r){
                if(r.code == 0){
                    alert('操作成功', function(index){
                        vm.reload();
                    });
                }else{
                    alert(r.msg);
                }
            }
        });
    });
}
/**
 * 验货确定
 */
function confirmReceive(rowId) {
    var rowData = $("#jqGrid").jqGrid('getRowData', rowId);
    var orderNo = rowData.orderNo;
    var message = "单号：<span class='text-primary'>"+ orderNo +"</span> 是否验货确定？";
    confirm(message, function(){
        var productionId = rowData.productionId;
        $.ajax({
            type: "GET",
            url: baseURL + "production/erporderproduction/confirmReceive",
            contentType: "application/json",
            data: {
                'productionId': productionId,
            },
            success: function(r){
                if(r.code == 0){
                    alert('操作成功', function(index){
                        vm.reload();
                    });
                }else{
                    alert(r.msg);
                }
            }
        });
    });
}
/**
 * 审核完成
 */
function auditFinish(rowId) {
    var rowData = $("#jqGrid").jqGrid('getRowData', rowId);
    var orderNo = rowData.orderNo;
    var message = "单号：<span class='text-primary'>"+ orderNo +"</span> 是否审核完成？";
    confirm(message, function(){
        var productionId = rowData.productionId;
        $.ajax({
            type: "GET",
            url: baseURL + "production/erporderproduction/auditFinish",
            contentType: "application/json",
            data: {
                'productionId': productionId,
            },
            success: function(r){
                if(r.code == 0){
                    alert('操作成功', function(index){
                        vm.reload();
                    });
                }else{
                    alert(r.msg);
                }
            }
        });
    });
}

/* 格式化报价商品addon */
Vue.directive('parsing-addon', function (el, binding) {
    var addon = binding.value;
    try {
        if (typeof JSON.parse(addon) == "object"){
            var jsonObj = JSON.parse(addon);
            var content = '';
            for (var a in jsonObj){
                var partsName = jsonObj[a].partsName;
                var text = partsName + '：';
                var basicParam = jsonObj[a].basicParam;
                if (!isBlank(basicParam)){
                    for (var b in basicParam){
                        text += ' ' + basicParam[b];
                    }
                }
                var craftParam = jsonObj[a].craftParam;
                if (!isBlank(craftParam)){
                    for (var c in craftParam){
                        text += ' ' + craftParam[c];
                    }
                }if (a == jsonObj.length - 1){
                    content += text
                }else {
                    content += text + '，'
                }
            }
            el.textContent = content;
            return
        }
    }catch (e){}
    el.textContent = addon
})

/* 商品类型为印刷、快印商品，从addon中获取数量 */
Vue.directive('parsing-num', function (el, binding) {
    var item = binding.value
    var nums = item.nums
    try {
        if (typeof JSON.parse(item.addon) == "object"){
            var jsonObj = JSON.parse(item.addon);
            for (var a in jsonObj){
                var basicParam = jsonObj[a].basicParam;
                if (!isBlank(basicParam)){
                    for (var b in basicParam){
                        if (b == '数量'){
                            nums = basicParam[b]
                            break
                        }
                    }
                }
            }
        }
    }catch (e){}
    el.textContent = nums
})

var vm = new Vue({
        el: '#rrapp',
        data: {
            showList: true,
            showOrder: false,
            showLogistics: false,
            showLogiNo: true,           // 是否显示配送单号
            showSendDetail: true,       // 是否显示发货明细
            showdeleteButton: true,     // 是否显示订单详情页面的删除按钮 true:显示 false:不显示
            erpOrderProduction: {},
            erpOrder: {},
            orderInfo: {},
            csIdList: [],
            remarkList: [],
            erpOrderItemEntityList: [],
            erpOrderProductionList: [],
            erpLogisticsEntity: {},      // 发货信息
            erpOrderItem: [],            // 订单明细
            logisticsItemList: [],      //勾选的订单明细
            userPaymentList: [], // 支付信息列表
            sellerInfoList: [],//自营门店列表
            pmcIdList:[], // 跟单员列表
            yangluoId: 343, //阳逻工厂ID
            q: {
                orderNo: '',
                productionOrder: '',
                productionStatus: '',
                financeStatus: '',
                examineStatus: '',
                producerName: '',
                producerType: '',
                sendGoodsType: '',
                pmcId: '',
                onlineCash: '',
                isquery: false,
                beginAllotTime: '',
                endAllotTime: '',
                shipStatus: '',
            },
            e: {
                orderProductionStatusEnum: [],
                producerTypeEnum: [],
                goodsTypeEnum: [],
                financeStatusEnum: [],
            },
            logisticsTypeList: [],
            /* 省市区data */
            area: [],
            /* 快递单 */
            formLabelWidth: '70px',
            expressFormVisible: false,
            expressForm: {},
            /* 订单调价 */
            costFormVisible: false,
            costForm: {
                discount: '',
                remark: '',
                productionId: ''
            },
            radio: '1',
            EMSView:false,
            sellerInfo:{},
            /* 源文件下载 */
            itemSourceFileTableVisible: false,
            itemFile: {
                itemSourceFiles: [],
            },
            /* 生产商列表 */
            producerOptions: [],
            producerLoading: false,
        },
        methods: {
            /* 订单起始 */
            checkBeginDate: function () {
                WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false, onpicking:function (dp) {
                        vm.q.beginAllotTime = dp.cal.getNewDateStr();
                    }})
            },
            /* 订单结束 */
            checkEndDate: function () {
                WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false, onpicking:function (dp) {
                        vm.q.endAllotTime = dp.cal.getNewDateStr();
                    }})
            },
            query: function () {
                vm.showList = true;
                vm.reload();
            },
            /* 查询重置 */
            reset: function () {
                vm.q.orderNo = '';
                vm.q.productionStatus = '';
                vm.q.financeStatus = '';
                vm.q.examineStatus = '';
                vm.q.productionOrder = '';
                vm.q.producerName = '';
                vm.q.producerType = '';
                vm.q.sendGoodsType = '';
                vm.q.pmcId = '';
                vm.q.onlineCash = '';
                vm.q.beginAllotTime = '';
                vm.q.endAllotTime = '';
                vm.q.shipStatus = '';
                vm.q.isquery = true;
                vm.reload();
            },
            /* 查询生产商信息 */
            getProducerData: function (query) {
                var self = this;
                self.producerLoading = true;
                $.get(baseURL + "production/erporderproduction/getProducerList?producerName=" + query, function (r) {
                    self.producerOptions = r.producerNames;
                    self.producerLoading = false;
                });
            },
            /* 获取订单详情信息 */
            erporderdetails: function(value){
                window.erporderAllotPageVm.getInfo({
                    orderNo: vm.erpOrder.orderNo,
                    showdeleteButton: vm.showdeleteButton
                });
            },
            send: function(){
                var productionIds = getSelectedRows();
                if(productionIds == null){
                    return ;
                }
                var that = this
                $.ajax({
                    type: "GET",
                    url: baseURL + "production/erporderproduction/sendLogisticsInfo/" + productionIds,
                    contentType: "application/json",
                    data: null,
                    success: function(r){
                        if(r.code == 0){
                            var areaData = r.area;
                            vm.area = JSON.parse(areaData);
                            vm.logisticsTypeList = r.logisticsTypeList;
                            vm.erpOrder = r.erpOrder;
                            vm.erpOrderItem = r.erpOrderItemEntityList;
                            that.$refs.multipleTable.toggleAllSelection();
                            vm.erpLogisticsEntity = {
                                toPeople: vm.erpOrder.shipName,
                               /* toPhone: vm.erpOrder.shipMobile + "," + vm.erpOrder.shipTel,*/
								toPhone:  vm.erpOrder.shipMobile+""+(vm.erpOrder.shipTel==null?"":","+vm.erpOrder.shipTel),
                                toAddress: vm.erpOrder.shipAddr,
                                toArea: vm.erpOrder.shipArea,
                                toAreaId: vm.erpOrder.shipAreaId,
                                sendType: 3,
                                logiType: 2
                            };
                            vm.showLogistics = true;
                            vm.showOrder = false;
                            vm.showList = false;
                        }else{
                            alert(r.msg);
                        }
                    }
                });
            },
            logiImport: function () {
                this.$refs.zyLogisticsImport.click();
            },
            reload: function (event) {
                vm.showList = true;
                vm.showOrder = false;
                vm.showLogistics = false;
                var isquery = vm.q.isquery;
                var page = $("#jqGrid").jqGrid('getGridParam','page');
                if (isquery){
                    page = 1;
                }
                vm.q.isquery = false;
                $("#jqGrid").jqGrid('setGridParam', {
                    page: page,
                    postData: {
                        'orderNo': vm.q.orderNo,
                        'productionStatus': vm.q.productionStatus,
                        'financeStatus': vm.q.financeStatus,
                        'examineStatus': vm.q.examineStatus,
                        'productionOrder': vm.q.productionOrder,
                        'producerName': vm.q.producerName,
                        'producerType': vm.q.producerType,
                        'sendGoodsType': vm.q.sendGoodsType,
                        'pmcId': vm.q.pmcId,
                        'onlineCash': vm.q.onlineCash,
                        'beginAllotTime': vm.q.beginAllotTime,
                        'endAllotTime': vm.q.endAllotTime,
                        'shipStatus': vm.q.shipStatus,
                    }
                }).trigger("reloadGrid");
            },
            reback: function () {
                vm.showList = true;
                vm.showOrder = false;
                vm.showLogistics = false;
            },
            logiTypeChange: function (value) {
                for (var i = 0, logisticsType; logisticsType = vm.logisticsTypeList[i++];) {
                    // 紫云物流 不填写配送单号
                    if (logisticsType.logisticsId == value){
                        vm.erpLogisticsEntity.logiCompany = logisticsType.logisticsName;
                        if (logisticsType.logisticsName.indexOf("紫云-") == 0){
                            vm.showLogiNo = false;
                        }
                    }else {
                        vm.showLogiNo = true;
                    }
                }
            },
            sendTypeChange: function (value) {
                if (value == 1) {
                    vm.showSendDetail = false;
                } else {
                    vm.showSendDetail = true;
                }
            },
            handleItemChange: function (val) {
                var values = val.join(',').split(',');
                var areaId = values[val.length - 1];
                vm.erpLogisticsEntity.toAreaId = areaId;

                var lableObj = getCascaderObj(val, vm.area);
                var lable = lableObj.join(',').replace(new RegExp(',', 'g'), ' ');
                vm.erpLogisticsEntity.toArea = lable;
            },
            //监听订单明细勾选change事件
            // orderItemSelectionChange: function (value) {
            orderItemSelectionChange: function (row) {
                var list = new Array();
                for (var i = 0, orderItem; orderItem = row[i++];) {
                    var logisticsItem = {
                        orderItemId: orderItem.originalItemId,
                        orderItemName: orderItem.name,
                        quantity: orderItem.nums
                    }
                    list.push(logisticsItem);
                }
                vm.logisticsItemList = list;
            },
            // 参数验证
            validator: function () {
                if(vm.erpLogisticsEntity.logiType != 3){
                    if (isBlank(vm.erpLogisticsEntity.logisticsId)) {
                        alert("物流方式不能为空");
                        return false;
                    }
                }
                if (isBlank(vm.erpLogisticsEntity.toPeople)) {
                    alert("收货人不能为空");
                    return false;
                } else if (isBlank(vm.erpLogisticsEntity.toAreaId)) {
                    alert(" 收货地区不能为空");
                    return false;
                } else if (isBlank(vm.erpLogisticsEntity.toArea)) {
                    alert("收货地址不能为空");
                    return false;
                }
                return true;
            },
            // 添加物流信息保存
            saveLogistics: function () {
                // 验证参数
                if (!vm.validator()) {
                    return false;
                }
                var erpLogisticsDto = {
                    erpLogisticsEntity: vm.erpLogisticsEntity,
                    erpLogisticsItemList: vm.logisticsItemList
                }
                erpLogisticsDto.erpLogisticsEntity.orderNo = vm.erpOrder.orderNo;
                erpLogisticsDto.erpLogisticsEntity.sellerId = vm.erpOrder.thirdMerchantId;
                erpLogisticsDto.erpLogisticsEntity.orderId = vm.erpOrder.originalOrderId;
                erpLogisticsDto.erpLogisticsEntity.fromPeople = "ziyun";
                erpLogisticsDto.erpLogisticsEntity.fromArea = "湖北 武汉 江汉区";
                erpLogisticsDto.erpLogisticsEntity.fromAddress = "江汉区常青三路17B9-13";
                erpLogisticsDto.erpLogisticsEntity.fromPhone = "400-000-2519";
                console.log(erpLogisticsDto);
                $.ajax({
                    type: "POST",
                    url: baseURL + "logistics/erplogistics/saveOrderLogisticsInfo",
                    contentType: "application/json",
                    data: JSON.stringify(erpLogisticsDto),
                    success: function (r) {
                        if (r.code === 0) {
                            alert('操作成功', function (index) {
                                vm.reload();
                            });
                        } else {
                            alert(r.msg);
                        }
                    }
                });
            },
            /* 显示源文件下载 */
            itemSourcePicsShow: function (id) {
                vm.itemFile.itemSourceFiles = [];
                $.get(baseURL + "production/erporderproduction/orderSourceFile?productionId=" + id, function (r) {
                    vm.itemFile.itemSourceFiles = r.userAccessoryList;
                });
                vm.itemSourceFileTableVisible = true;
            },
            /* 商品原文件下载 */
            itemSourceFileDownload: function (data) {
                window.location.href = baseURL + "order/useraccessory/download/" + data.id;
            },
            /* 显示调价框 */
            discountView: function (productionId, discount) {
                vm.costFormVisible = true;
                vm.costForm.productionId = productionId;
                vm.costForm.discount = discount;
            },
            /* 订单调价 */
            orderDiscount: function () {
                var discount = vm.costForm.discount;
                if (discount == ''){
                    alert("调价不能为空");
                    return false;
                }

                var remark = vm.costForm.remark;
                if (isBlank(remark)){
                    alert("调价原因不能为空");
                    return false;
                }
                var productionId = vm.costForm.productionId;
                var postData = {
                    productionId: productionId,
                    discount: discount,
                    remark: remark
                }
                $.ajax({
                    type: "POST",
                    url: baseURL + "production/erporderproduction/orderDiscount",
                    contentType: "application/json",
                    data: JSON.stringify(postData),
                    success: function(r){
                        if(r.code == 0){
                            vm.reload();
                            vm.costFormVisible = false;
                        }else{
                            alert(r.msg);
                        }
                    }
                });
            },
            /* 格式化报价产品规格 */
            parsingAddon(addon){
                try {
                    if (typeof JSON.parse(addon) == "object"){
                        var jsonObj = JSON.parse(addon);
                        var content = '';
                        for (var a in jsonObj){
                            var partsName = jsonObj[a].partsName;
                            var text = partsName + '：';
                            var basicParam = jsonObj[a].basicParam;
                            if (!isBlank(basicParam)){
                                for (var b in basicParam){
                                    text += ' ' + basicParam[b];
                                }
                            }
                            var craftParam = jsonObj[a].craftParam;
                            if (!isBlank(craftParam)){
                                for (var c in craftParam){
                                    text += ' ' + craftParam[c];
                                }
                            }if (a == jsonObj.length - 1){
                                content += text
                            }else {
                                content += text + '，'
                            }
                        }
                        return content
                    }
                }catch (e){}
                return addon
            },
            /* 格式化报价商品属性显示 */
            formatAddon(row, column, cellValue, index){
                var addcartBuyType = row.addcartBuyType;
                if (addcartBuyType == 'print' || addcartBuyType == 'fast'){
                    try {
                        if (typeof JSON.parse(cellValue) == "object"){
                            var jsonObj = JSON.parse(cellValue);
                            var content = '';
                            for (var a in jsonObj){
                                var partsName = jsonObj[a].partsName;
                                var text = partsName + '：';
                                var basicParam = jsonObj[a].basicParam;
                                if (!isBlank(basicParam)){
                                    for (var b in basicParam){
                                        text += ' ' + basicParam[b];
                                    }
                                }
                                var craftParam = jsonObj[a].craftParam;
                                if (!isBlank(craftParam)){
                                    for (var c in craftParam){
                                        text += ' ' + craftParam[c];
                                    }
                                }
                                if (a == jsonObj.length - 1){
                                    content += text
                                }else {
                                    content += text + '，'
                                }
                            }
                            return content;
                        }
                    }catch (e){}
                }
                return cellValue;
            },
            // 弹出送货单
            createPrintPage: function () {
                LODOP = getLodop();
                LODOP.PRINT_INIT("Lodop初始化");
                LODOP.SET_PRINT_PAGESIZE(1, 2100, 1300, ""); //第一个参数为1表示纵向
                LODOP.ADD_PRINT_HTM(0, "3%", "95%", "100%", document.getElementById("printbox").innerHTML);
                /*增加超文本项*/
            },
            //打印送货单
            printGoods: function (orderNo) {
                $.get(baseURL + "order/erporder/info/" + orderNo, function (r) {
                    vm.erpOrder = r.erpOrder;
                    vm.erpOrderItem = r.erpOrderItemEntityList;
                    LODOP = getLodop();
                    LODOP.PRINT_INIT("");
                    layer.open({
                        type: 1,
                        skin: 'layui-layer-molv',
                        title: "打印送货单",
                        area: ['800px', '550px'],
                        shadeClose: false,
                        content: jQuery("#printGoods"),
                        btn: ['打印', '取消'],
                        btn1: function (index) {
                            vm.createPrintPage();
                            LODOP.PRINT();
                            // LODOP.PREVIEW();
                        }
                    });
                });
            },
            //弹出打印快递单
            showEMS(orderNo) {
                //获取收货人和发货人信息
                $.get(baseURL + "production/erporderproduction/expressFormInfo/" + orderNo, function (r) {
                    vm.erpOrder = r.erpOrder;
                    vm.sellerInfo = r.sellerInfo;
                    LODOP = getLodop();
                    LODOP.PRINT_INIT("");
                    vm.EMSView = true
                });
            },
            //打印快递单
            printEMS() {
                //初始化快递单
                LODOP = getLodop();
                LODOP.PRINT_INIT("初始化快递单");
                LODOP.SET_PRINT_PAGESIZE(1, 2200, 1200 , "");
                LODOP.SET_PRINT_STYLE("FontSize", 9);
                if (vm.radio == 1) {//韵达
                    LODOP.ADD_PRINT_TEXT(101, 110, 150, 25, vm.sellerInfo.sellerName);  //寄件人姓名
                    LODOP.ADD_PRINT_TEXT(101, 295, 150, 25, vm.sellerInfo.area);  //始发地城市
                    LODOP.ADD_PRINT_TEXT(126, 110, 302, 25, vm.sellerInfo.doorheadName);  //单位名称
                    LODOP.ADD_PRINT_TEXT(151, 110, 302, 25, vm.sellerInfo.addr);  //寄件地址1
                    LODOP.ADD_PRINT_TEXT(201, 110, 150, 25, vm.sellerInfo.sellerMobile); //联系电话1
                    LODOP.ADD_PRINT_TEXT(201, 254, 150, 25, vm.sellerInfo.shipZip);  //邮政编码1

                    LODOP.ADD_PRINT_TEXT(101, 470, 150, 25, vm.erpOrder.shipName);  //收件人姓名
                    LODOP.ADD_PRINT_TEXT(101, 645, 150, 25, vm.erpOrder.shipArea);  //目的地城市
                    LODOP.ADD_PRINT_TEXT(126, 470, 302, 25, vm.erpOrder.memberName);  //单位名称
                    LODOP.ADD_PRINT_TEXT(151, 470, 302, 25, vm.erpOrder.shipAddr);  //收件地址2
                    LODOP.ADD_PRINT_TEXT(201, 470, 150, 25, vm.erpOrder.shipMobile);  //联系电话2
                    LODOP.ADD_PRINT_TEXT(201, 596, 150, 25, vm.erpOrder.shipZip);  //邮政编码2
                }else if (vm.radio == 2) {//中通
                    LODOP.ADD_PRINT_TEXT(101, 110, 150, 25, vm.sellerInfo.sellerName);  //寄件人姓名
                    LODOP.ADD_PRINT_TEXT(101, 295, 150, 25, vm.sellerInfo.area);  //始发地城市
                    LODOP.ADD_PRINT_TEXT(126, 110, 302, 25, vm.sellerInfo.addr);  //寄件地址1
                    LODOP.ADD_PRINT_TEXT(151, 110, 302, 25, vm.sellerInfo.doorheadName );  //单位名称
                    LODOP.ADD_PRINT_TEXT(201, 110, 150, 25, vm.sellerInfo.sellerMobile); //联系电话1
                    LODOP.ADD_PRINT_TEXT(201, 254, 150, 25, vm.sellerInfo.shipZip);  //邮政编码1

                    LODOP.ADD_PRINT_TEXT(101, 470, 150, 25, vm.erpOrder.shipName);  //收件人姓名
                    LODOP.ADD_PRINT_TEXT(101, 645, 150, 25, vm.erpOrder.shipArea);  //目的地城市
                    LODOP.ADD_PRINT_TEXT(126, 470, 302, 25, vm.erpOrder.shipAddr);  //收件地址2
                    LODOP.ADD_PRINT_TEXT(151, 470, 302, 25, vm.erpOrder.memberName);  //单位名称
                    LODOP.ADD_PRINT_TEXT(201, 470, 150, 25, vm.erpOrder.shipMobile);  //联系电话2
                    LODOP.ADD_PRINT_TEXT(201, 596, 150, 25, vm.erpOrder.shipZip);  //邮政编码2
                }else if (vm.radio == 3) {//速尔
                    LODOP.ADD_PRINT_TEXT(101, 90, 150, 25, vm.sellerInfo.sellerName);  //寄件人
                    LODOP.ADD_PRINT_TEXT(101, 240, 150, 25, vm.sellerInfo.area);  //始发地城市
                    LODOP.ADD_PRINT_TEXT(126, 90, 302, 25, vm.sellerInfo.doorheadName);  //寄件公司
                    LODOP.ADD_PRINT_TEXT(151, 90, 350, 50, vm.sellerInfo.area+vm.sellerInfo.addr);  //详细地址

                    LODOP.ADD_PRINT_TEXT(176, 90, 150, 25, vm.erpOrder.shipName);  //收件人
                    LODOP.ADD_PRINT_TEXT(176, 240, 150, 25, vm.erpOrder.shipMobile);  //电话
                    LODOP.ADD_PRINT_TEXT(201, 90, 302, 25, vm.erpOrder.memberName); //收件公司
                    LODOP.ADD_PRINT_TEXT(226, 90, 350, 50, vm.erpOrder.shipArea+vm.erpOrder.shipAddr);  //详细地址
                }
                LODOP.PRINT();
                // LODOP.PREVIEW();
            },
        },
    })
;

/**
 * 省市区级联选择
 * @param val
 * @param opt
 */
function getCascaderObj(val, opt) {
    return val.map(function (value, index, array) {
        for (var itm in opt) {
            if (opt[itm].value == value) {
                var label = opt[itm].label;
                opt = opt[itm].children;
                return label;
            }
        }
        return null;
    });
}

/** 数字金额大写转换(可以处理整数,小数,负数) */
function smalltoBIG(n) {
    var fraction = ['角', '分'];
    var digit = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'];
    var unit = [['元', '万', '亿'], ['', '拾', '佰', '仟']];
    var head = n < 0 ? '欠' : '';
    n = Math.abs(n);

    var s = '';

    for (var i = 0; i < fraction.length; i++) {
        s += (digit[Math.floor(n * 10 * Math.pow(10, i)) % 10] + fraction[i]).replace(/零./, '');
    }
    s = s || '整';
    n = Math.floor(n);

    for (var i = 0; i < unit[0].length && n > 0; i++) {
        var p = '';
        for (var j = 0; j < unit[1].length && n > 0; j++) {
            p = digit[n % 10] + unit[1][j] + p;
            n = Math.floor(n / 10);
        }
        s = p.replace(/(零.)*零$/, '').replace(/^$/, '零') + unit[0][i] + s;
    }
    return head + s.replace(/(零.)*零元/, '元').replace(/(零.)+/g, '零').replace(/^整$/, '零元整');
}